home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-18 | 2.9 KB | 97 lines | [TEXT/CWIE] |
- //=====================================================================================
- // SwitchFinder.cp
- //
- // A FinderPoplet to switch to the Finder and hide others.
- // Does this by furtling with the process menu. Nasty. Yeah.
- //
- //
- // Written by: turly o’connor, cork, ireland turly@geocities.com
- //
- // Copyright: 1997, 1998 by Turlough O'Connor, all rights reserved.
- //
- // Change History (most recent first):
- // <01> 03-Oct-98 tur Basic Version
- //
- //=====================================================================================
-
- #include <MacTypes.h>
- #include "FinderPopAPI.h"
-
- enum {kFinderType = 'FNDR', kFinderCreator = 'MACS'}; // Finder file info
-
- static OSErr FindProcess(OSType typeToFind, OSType creatorToFind, ProcessSerialNumber *processSN);
-
- //
- // if we're being called for the first time, detach ourselves in case the host app quits
- // and our Fplt file ends up being closed underneath us!
- //
-
- pascal UInt32 main(TFinderPopletInfo *info)
- {
- UInt32 retVal = (info->fpltRefCon != 0) ? kFinderPopletContinue : kFinderPopletDetachAndStayResident;
-
- if (1) // (info->fpltEvent != NULL && info->fpltEvent->what == nullEvent)
- {
- ProcessSerialNumber finderPSN, frontPSN;
- Boolean sameProcess;
-
- info->fpltRefCon++; // #times we were called...
- sameProcess = false;
-
- if (GetFrontProcess(&frontPSN) == noErr)
- {
- if (FindProcess(kFinderType, kFinderCreator, &finderPSN) == noErr)
- {
- if (SameProcess(&frontPSN, &finderPSN, &sameProcess) == noErr)
- {
- if (sameProcess) // Finder is already frontmost
- { // so furtle with SysMenu to "Hide Others"
- SystemMenu(0xBF970002); // System Menu, Item #2 -- yuck!
- retVal = kFinderPopletTerminate;
- }
- else // try bringing the Finder frontmost
- SetFrontProcess(&finderPSN);
- }
- }
- }
- }
-
- if (info->fpltRefCon > 30) // called more than 30 times? Abort.
- { // There's probably a dialog up or something...
- SysBeep(0);
- retVal = kFinderPopletTerminate;
- }
-
- return retVal;
- }
-
- //===================================================================================
- // FindProcess
- //
- // Search through the current process list to find the given application.
- //
- //===================================================================================
-
- static OSErr FindProcess(OSType typeToFind, OSType creatorToFind, ProcessSerialNumber *processSN)
- {
- ProcessInfoRec tempInfo;
- OSErr err = noErr;
- // start at the beginning of the process list
- processSN->lowLongOfPSN = kNoProcess;
- processSN->highLongOfPSN = kNoProcess;
-
- tempInfo.processInfoLength = sizeof(ProcessInfoRec);
- tempInfo.processName = NULL;
- tempInfo.processAppSpec = NULL;
-
- do
- {
- err = GetNextProcess(processSN);
- if (err == noErr)
- err = GetProcessInformation(processSN, &tempInfo);
- }
- while (err == noErr && (tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind));
-
- return err;
- } // FindProcess
-